package com.example.common.slice;

import com.example.common.ResourceTable;
import com.example.common.model.bean.JavaCourse;
import com.example.common.presenter.DetailAbilityPresenter;
import com.example.common.provider.ItemProvider;
import com.example.commonlib.base.ToolbarAbility;
import com.example.commonlib.base.presenter.RequirePresenter;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ListContainer;

import java.util.ArrayList;
import java.util.List;

@RequirePresenter(DetailAbilityPresenter.class)
public class DetailAbilitySlice extends ToolbarAbility<DetailAbilityPresenter> {
    // 整个页面
    private ComponentContainer detailLayout;
//    private ListContainer mRecyclerView;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setStatusPageEnable(true);
        // 由于无法直接 通过 RsId setUI, 所以 通过下面获取componentContainer，再set
        LayoutScatter getLayoutInflater = LayoutScatter.getInstance(getContext());
        detailLayout = (ComponentContainer)getLayoutInflater.parse(ResourceTable.Layout_slice_detail, null, false);

        // set UI
        setUIContent(detailLayout);
        // 设置显隐藏 返回
        setToolbarHomeBack(true);
        // 设置 tilte
        setTitle(ResourceTable.String_courseDetailTitle);
        // 设置左侧icon
        setLeftIcon(ResourceTable.Media_iconBack);
        // 隐藏右侧按钮
        setRightVisibility(false);

        //initListContainer();
    }

    // toolbar 继承返回点击事件
    @Override
    public void backEvent(){
        // 返回
        super.onBackPressed();
    }

    private void initListContainer() {
        ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_list_container);
        List<JavaCourse> list = new ArrayList<>();
        ItemProvider sampleItemProvider = new ItemProvider(list, getContext());
        listContainer.setItemProvider(sampleItemProvider);
    }
}
